All Questions
6 questions
0votes
1answer
571views
Sort a stack using Java
This is my attempted solution to cracking the coding interview exercise 3.5. Looking for any feedback on coding style or the algorithm anywhere I can improve really. The problem specification is as ...
4votes
1answer
2kviews
Sort stack using two stacks
My program is supposed to sort a stack such that the smallest item are on the top. I can use a temporary stack, but you may not copy the elements into any other data structure. The program works ...
4votes
1answer
4kviews
Sort a stack in descending order
Maintain current element as the top element in the input stack. Pop all the elements on the ordered stack which are greater than the current element and push them in to the input stack and maintain a ...
3votes
3answers
3kviews
Sort stack in ascending order
I am using two more helper stacks to sort. Kindly suggest improvements in terms of space and time. ...
4votes
2answers
7kviews
Sorting a Stack in ascending order
Here's my implementation of sorting a stack in ascending order. The problem statement is as follows : Write a program to sort a stack in ascending order (with biggest items on top). You may use at ...
5votes
1answer
5kviews
Sort a stack in ascending order
Sort a stack in ascending order. You may only use one additional stack to hold items. Any comments on my solution? Worst case complexities: Memory complexity: O(n) Runtime complexity: O(n^2) Also, ...